import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:wy/utils/screen_util.dart';

class HPlayerInner extends HookWidget {
  final bool playing;
  const HPlayerInner({Key key, this.playing = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final screen = Screen(context);
    final d = useState(0.0);

    Timer(Duration(milliseconds: 16), () {
      if (playing) {
        d.value += 1;
      }
    });

    return Container(
      height: screen.calc(800),
      child: Stack(
        children: [
          // 唱片
          Positioned(
              left: screen.calc((750 - 618) / 2),
              top: screen.calc(182),
              child: Transform.rotate(
                angle: d.value * pi / 180,
                child: Container(
                  width: screen.calc(618),
                  height: screen.calc(618),
                  child: Stack(
                    children: [
                      //封面
                      Center(
                          child: Container(
                        color: Colors.black,
                        child: Image.asset('assets/images/tmp_cover_7.jpg',
                            width: screen.calc(400), height: screen.calc(400)),
                      )),
                      //唱片
                      Positioned.fill(
                          child: Image.asset('assets/images/player-disc.png'))
                    ],
                  ),
                ),
              )),
          //arm
          Positioned(
            left: screen.calc(325),
            top: screen.calc(24),
            child: Transform.rotate(
              origin: Offset(screen.calc(-137), screen.calc(-80)),
              angle: playing ? 30 * pi / 180 : 0,
              child: Image.asset('assets/images/player-arm.png',
                  width: screen.calc(314), height: screen.calc(198)),
            ),
          ),
        ],
      ),
    );
  }
}
